<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API 文档</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        h1, h2, h3 {
            color: #2c3e50;
        }
        .endpoint {
            margin-bottom: 20px;
        }
        .endpoint-method {
            font-weight: bold;
            color: #3498db;
        }
        .endpoint-path {
            font-weight: bold;
            color: #2ecc71;
        }
        .description {
            margin-bottom: 10px;
        }
        .request {
            margin-bottom: 10px;
        }
        .response {
            margin-bottom: 20px;
        }
        .code-block {
            background-color: #f5f5f5;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            overflow-x: auto;
        }
        .parameter-description {
            margin-bottom: 10px;
            font-style: italic;
        }
    </style>
</head>
<body>
    <h1>API 文档</h1>
    <h2>表操作路由</h2>
    <div class="endpoint">
        <div class="endpoint-method">GET</div>
        <div class="endpoint-path">/tables</div>
        <div class="description">获取数据库中所有表的列表。</div>
        <div class="request">无需请求体。</div>
        <div class="response">返回一个包含表名的JSON数组。</div>
        <div class="code-block">
            <pre>
                <code>
[
    "qwq",
    "your_table_name",
    "another_table"
]
                </code>
            </pre>
        </div>
        <div class="error-handling">
            <div class="error-code">500 Internal Server Error</div>
            <div class="error-description">如果数据库查询失败。</div>
        </div>
    </div>
    <div class="endpoint">
        <div class="endpoint-method">POST</div>
        <div class="endpoint-path">/tables</div>
        <div class="description">在数据库中创建一个新表。</div>
        <div class="request">包含表名和列定义的JSON请求体。</div>
        <div class="code-block">
            <pre>
                <code>
{
    "table_name": "new_table",
    "columns": {
        "id": "INT AUTO_INCREMENT PRIMARY KEY",
        "name": "VARCHAR(255)",
        "age": "INT"
    }
}
                </code>
            </pre>
        </div>
        <div class="request">必须要一个"id": "INT AUTO_INCREMENT PRIMARY KEY"</div>
        <div class="response">成功时返回201 Created。</div>
        <div class="error-handling">
            <div class="error-code">400 Bad Request</div>
            <div class="error-description">如果表名包含非法字符。</div>
            <div class="error-code">500 Internal Server Error</div>
            <div class="error-description">如果数据库查询失败。</div>
        </div>
    </div>
    <div class="endpoint">
        <div class="endpoint-method">DELETE</div>
        <div class="endpoint-path">/tables/:table_name</div>
        <div class="description">从数据库中删除一个表。</div>
        <div class="parameter-description">
            <strong>:table_name</strong> 是要删除的表名，必须是数据库中已存在的表名。
        </div>
        <div class="request">无需请求体。</div>
        <div class="response">成功时返回204 No Content。</div>
        <div class="error-handling">
            <div class="error-code">400 Bad Request</div>
            <div class="error-description">如果表名包含非法字符。</div>
            <div class="error-code">500 Internal Server Error</div>
            <div class="error-description">如果数据库查询失败。</div>
        </div>
    </div>
    <h2>数据项操作路由</h2>
    <div class="endpoint">
        <div class="endpoint-method">GET</div>
        <div class="endpoint-path">/tables/:table_name/items</div>
        <div class="description">获取指定表中的所有数据项。</div>
        <div class="parameter-description">
            <strong>:table_name</strong> 是目标表的表名，必须是数据库中已存在的表名。
        </div>
        <div class="request">无需请求体。</div>
        <div class="response">返回一个包含数据项的JSON数组。</div>
        <div class="code-block">
            <pre>
                <code>
[
    {
        "id": 1,
        "name": "Kimi",
        "age": "25"
    },
    {
        "id": 2,
        "name": "Alice",
        "age": "30"
    }
]
                </code>
            </pre>
        </div>
        <div class="error-handling">
            <div class="error-code">400 Bad Request</div>
            <div class="error-description">如果表名包含非法字符。</div>
            <div class="error-code">500 Internal Server Error</div>
            <div class="error-description">如果数据库查询失败。</div>
        </div>
    </div>
    <div class="endpoint">
        <div class="endpoint-method">POST</div>
        <div class="endpoint-path">/tables/:table_name/items</div>
        <div class="description">在指定表中创建一个新的数据项。</div>
        <div class="parameter-description">
            <strong>:table_name</strong> 是目标表的表名，必须是数据库中已存在的表名。
        </div>
        <div class="request">包含数据项内容的JSON请求体。</div>
        <div class="code-block">
            <pre>
                <code>
{
	"data": {
        "name": "Bob",
    	"age": "28"
    }
}
                </code>
            </pre>
        </div>
        <div class="response">成功时返回201 Created。</div>
        <div class="error-handling">
            <div class="error-code">400 Bad Request</div>
            <div class="error-description">如果表名包含非法字符。</div>
            <div class="error-code">500 Internal Server Error</div>
            <div class="error-description">如果数据库查询失败。</div>
        </div>
    </div>
    <div class="endpoint">
        <div class="endpoint-method">PUT</div>
        <div class="endpoint-path">/tables/:table_name/items/:id</div>
        <div class="description">更新指定表中的一个数据项。</div>
        <div class="parameter-description">
            <strong>:table_name</strong> 是目标表的表名，必须是数据库中已存在的表名。<br>
            <strong>:id</strong> 是要更新的数据项的ID。
        </div>
        <div class="request">包含更新内容的JSON请求体。</div>
        <div class="code-block">
            <pre>
                <code>
{
	"name": "Bob Updated",
        "age": "29"
}
                </code>
            </pre>
        </div>
        <div class="response">成功时返回204 No Content。</div>
        <div class="error-handling">
            <div class="error-code">400 Bad Request</div>
            <div class="error-description">如果表名包含非法字符。</div>
            <div class="error-code">500 Internal Server Error</div>
            <div class="error-description">如果数据库查询失败。</div>
        </div>
    </div>
    <div class="endpoint">
        <div class="endpoint-method">DELETE</div>
        <div class="endpoint-path">/tables/:table_name/items/:id</div>
        <div class="description">从指定表中删除一个数据项。</div>
        <div class="parameter-description">
            <strong>:table_name</strong> 是目标表的表名，必须是数据库中已存在的表名。<br>
            <strong>:id</strong> 是要删除的数据项的ID。
        </div>
        <div class="request">无需请求体。</div>
        <div class="response">成功时返回204 No Content。</div>
        <div class="error-handling">
            <div class="error-code">400 Bad Request</div>
            <div class="error-description">如果表名包含非法字符。</div>
            <div class="error-code">500 Internal Server Error</div>
            <div class="error-description">如果数据库查询失败。</div>
        </div>
    </div>
</body>
</html>